﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Kokomo
{
	/// <summary>
	/// Extends the functionality of <see cref="Delegate"/>.
	/// </summary>
	public static class DelegateExtensions
	{
		/// <summary>
		/// Gets the Invoke method.
		/// </summary>
		/// <param name="delegate">The @delegate.</param>
		/// <returns></returns>
		public static MethodInfo GetInvokeMethod(this Delegate @delegate)
		{
			ArgumentValidation.CheckNullArgument("delegate", @delegate);
			return @delegate.GetType().GetMethod("Invoke");
		}

		public static Action<TArgBase> CreateThunk<TArg, TArgBase>(
			this Action<TArg> action
			)
			where TArg : TArgBase
		{
			return arg => action((TArg)arg);
		}
	}
}
